package study.mybatis.multi.datasource.support.datasource;

import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Slf4j
@Configuration
public class DataSourceConfig {

    @Primary
    @Bean(name = "userDataSource")
    @ConfigurationProperties(prefix = "ds.user")
    public DataSource userDataSource() {
//        DataSource dataSource = new DruidDataSource();
        DataSource dataSource = DataSourceBuilder.create().build();
        log.info(">>>>>> {}", dataSource.getClass().getName());
        return dataSource;
    }

    @Bean(name = "accountDataSource")
    @ConfigurationProperties(prefix = "ds.account")
    public DataSource accountDataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        log.info(">>>>>> account= {}", dataSource.getJdbcUrl());
        return dataSource;
    }
}
